<template>
	<view>
		<!-- //标题 -->
		<view class="top-box tn-cool-bg-color-15--reverse">
			<view class="text-lg margin-left-lg text-bold  padding-xs">{{timeGet}}</view>
			<view class="text-lg text-bold">楼栋长订单管理</view>
			<view class="text-lg margin-right-sm text-bold  padding-xs" style="border-radius: 10rpx;" @click="shuaxin">
				刷新</view>
		</view>

		<view style="margin-top: 30rpx;margin-bottom: 20rpx;"
			class="login__mode tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-center">
			<view class="login__mode__item tn-flex-1" :class="[{'login__mode__item--active': currentModeIndex === 0}]"
				@tap.stop="modeSwitch(0)">
				未送
			</view>
			<view class="login__mode__item tn-flex-1" :class="[{'login__mode__item--active': currentModeIndex === 1}]"
				@tap.stop="modeSwitch(1)">
				已送
			</view>
			<!-- 滑块-->
			<view class="login__mode__slider tn-cool-bg-color-15--reverse" :style="[modeSliderStyle]"></view>
		</view>

		<view class="text-lg text-bold " v-if="currentModeIndex==0" style="margin: 30rpx;font-size: 45rpx;">{{louname}}:目前共计{{count}}单</view>
		<view class="text-lg text-bold " v-else style="margin: 30rpx;font-size: 45rpx;">{{louname}}:目前共计{{yscount}}单</view>

		<block v-if="currentModeIndex==0">
			<view class="main-content">
				<view class="list">
					<view class="text-bold text-lg text-black margin-left-xs">时间</view>
					<view class="text-lg text-black text-bold margin-right-lg" style="flex: 1; text-align: end;">未送单量
					</view>
				</view>
			</view>
			<view class="main-content">
				<view v-for="(item,index) in timeList" :key="index" class="list" @click="toTimeSet(item.time)">
					<view class="text-lg text-bold margin-left-xs">{{item.time}}</view>
					<view class="text-red text-xxl text-bold margin-right-lg" style="flex: 1; text-align: end;">
						{{item.count}}</view>
				</view>
			</view>
		</block>
		<block v-else>
			<view class="main-content">
				<view class="list">
					<view class="text-bold text-lg text-black margin-left-xs">时间</view>
					<view class="text-lg text-black text-bold margin-right-lg" style="flex: 1; text-align: end;">已送单量
					</view>
				</view>
			</view>
			<view class="main-content">
				<view v-for="(item,index) in ystimeList" :key="index" class="list" @click="toTimeSet(item.time)">
					<view class="text-lg text-bold margin-left-xs">{{item.time}}</view>
					<view class="text-red text-xxl text-bold margin-right-lg" style="flex: 1; text-align: end;">
						{{item.count}}</view>
				</view>
			</view>
		</block>

	</view>
</template>

<script>
	//时间
	//数据库引入
	const db = uniCloud.database();
	const dbCmd = db.command;
	//引入全局变量
	var app = getApp();
	export default {
		data() {
			return {
				timeGet: '',
				count: 0,
				yscount:0,
				timeList: [],
				ystimeList: [],
				// 当前选中的模式
				currentModeIndex: 0,
				// 模式选中滑块
				modeSliderStyle: {
					left: 0
				},
				storeList: [],
				lou: 1,
				louname: "",
				super: false,
				openid:""
			}
		},
		watch: {
			currentModeIndex(value) {
				const sliderWidth = uni.upx2px(476 / 2)
				this.modeSliderStyle.left = `${sliderWidth * value}px`
			},
		},
		onLoad(options) {
			this.super = options.super;
			this.louname = options.louname
			this.school = options.school
			// this.openid="oryqr6fcWZdnLWZ6OYa1NzymSza0"
			this.chechLogin();
		},
		onShow() {
			let that = this;
			//初始化订单
			that.getLouAllOrder();
		},
		methods: {
			//判断登陆
			chechLogin() {
				let that = this;
				uni.getStorage({
					key: 'user_sxz',
					success(res) {
						console.log('获取到store本地数据', res);
						that.openid = res.data.openid;
						console.log("哈哈",that.openid);
						//判断是否登陆
						if (that.openid == '' || that.openid == undefined) {
							uni.showModal({
								title: '您还没有绑定微信登陆，是否要现在进行绑定？',
								success(res) {
									uni.switchTab({
										url: '../../../me/me'
									});
									return;
								}
							});
						}
					},
					fail(res) {
						console.log('获取失败', res);
						if(app.globalData.openid!=-1){
							if (app.globalData.openid == undefined || app.globalData.openid == '') {
								uni.showModal({
									title: '您还没有绑定微信登陆，是否要现在进行绑定？',
									success(res) {
										uni.switchTab({
											url: '../../../me/me'
										});
										return;
									}
								});
							}else{
								that.openid = app.globalData.openid
							}
						}
						else{
							uni.showModal({
								title: '您还没有绑定微信登陆，是否要现在进行绑定？',
								success(res) {
									uni.switchTab({
										url: '../../../me/me'
									});
									return;
								}
							});
						}
					}
				});
			},
			// 切换模式
			modeSwitch(index) {
				this.currentModeIndex = index
			},
			//刷新订单
			shuaxin() {
				let that = this;
				that.getLouAllOrder();
			},
			//跳转到具体时间点订单
			toTimeSet(time) {
				if (this.super == false || this.super == undefined) {
					console.log('输出时间：', time);
					uni.navigateTo({
						url: `timeDetail?timeGive=${time}&louname=${this.louname}&openid=${this.openid}&school=${this.school}`
					})
				} else {
					var url = `timeDetail?timeGive=${time}&louname=${this.louname}&super=true&openid=${this.openid}&school=${this.school}`
					uni.navigateTo({
						url: url
					})
				}
			},
			//获取某楼栋所有订单
			getLouAllOrder(){
				let that = this;
				//初始化
				that.count = 0;
				that.yscount = 0;
				//TODO:楼栋长需要修改的地方
				uni.showLoading({
					title:"正在获取数据..."
				})
				
				uni.request({
					url:"https://zback.shixiaozhu.work/ShixiaozhuTest/order/getWeisongOrderNumForLou?addressName="+that.louname+"&oSchool="+that.school,
					success(res) {
						that.timeList = res.data.data
						for (var i = 0; i < that.timeList.length; i++) {
							that.count = that.count+that.timeList[i].count
						}
						uni.request({
							url:"https://zback.shixiaozhu.work/ShixiaozhuTest/order/getOrderNumForLou?addressName="+that.louname+"&oSchool="+that.school,
							success(res) {
								that.ystimeList = res.data.data
								console.log("hh",this.louname)
								for (var i = 0; i < that.ystimeList.length; i++) {
									that.yscount = that.yscount+that.ystimeList[i].count
								}
								uni.hideLoading()
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login__info__item__button {
		width: 180rpx;
		padding: 10rpx;
		border-radius: 5px;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		justify-content: center;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.login {
		position: relative;
		height: 100%;
		z-index: 1;

		/* 内容 start */
		&__wrapper {
			padding-top: 120rpx;
			width: 100%;
		}

		/* 切换 start */
		&__mode {
			position: relative;
			margin: 0 auto;
			width: 476rpx;
			height: 77rpx;
			background-color: rgba(255, 255, 255, 0.2);
			backdrop-filter: blur(6rpx);
			-webkit-backdrop-filter: blur(6rpx);
			box-shadow: 0rpx 10rpx 50rpx 0rpx rgba(0, 3, 72, 0.1);
			border-radius: 39rpx;

			&__item {
				height: 77rpx;
				width: 100%;
				line-height: 77rpx;
				text-align: center;
				font-size: 31rpx;
				color: #000000;
				font-weight: bold;
				letter-spacing: 1em;
				text-indent: 1em;
				z-index: 2;
				transition: all 0.4s;

				&--active {
					font-weight: bold;
					color: #FFFFFF;
				}
			}

			&__slider {
				position: absolute;
				height: inherit;
				width: calc(476rpx / 2);
				border-radius: inherit;
				box-shadow: 0rpx 18rpx 72rpx 18rpx rgba(0, 195, 255, 0.1);
				z-index: 1;
				transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
			}
		}
	}


	.top-box {
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.list {
		width: 100%;
		height: 100rpx;
		display: flex;
		border: 1rpx solid #e6e6e6;
		align-items: center;
		/* 		margin-bottom: 10rpx; */
		background-color: #ffffff;
	}
</style>
